package com.sb.money.dao.impl;

import com.sb.money.dao.AbstractDao;

import java.io.Serializable;
import java.util.List;

import org.apache.tapestry5.annotations.Log;
import org.apache.tapestry5.ioc.annotations.Inject;

import org.hibernate.Session;

/**
 * @author Stefan Bertos
 * @param <E>
 *            entity
 */
public abstract class AbstractDaoImpl<E extends Serializable> implements
        AbstractDao<E> {

    /**
     * Inject Hibernate session.
     */
    @Inject
    private Session session;

    /**
     * default constructor.
     */
    public AbstractDaoImpl() {
        super();
    }

    @Log
    @Override
    public final E create(final E entity) {
        this.getSession().save(entity);
        return entity;
    }

    @Log
    @Override
    public final void update(final E entity) {
        this.getSession().saveOrUpdate(entity);
    }

    @Log
    @Override
    public final void delete(final E entity) {
        this.getSession().delete(entity);
    }

    /**
     * @return List of entitities
     */
    @Log
    public List<E> findAll() {
        return null;
    }

    /**
     * @return the session
     */
    public final Session getSession() {
        return this.session;
    }

    /**
     * @param pSession
     *            the session to set
     */
    public final void setSession(final Session pSession) {
        this.session = pSession;
    }
}